package com.survey.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.junit.Test;

public class DataUtil {
	/**
	 * MD5加密算法
	 */
	public static String md5(String src){
		StringBuffer buffer=new StringBuffer();
		try {
			char[] chars={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
			byte[] bytes=src.getBytes();
			MessageDigest  md=MessageDigest.getInstance("MD5");
			byte[] targ=md.digest(bytes);
			for(byte b:targ){
				buffer.append(chars[(b>>4)&0x0F]);
				buffer.append(chars[b&0x0F]);
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return buffer.toString();
	}
}

